//
//  CompoundSuccessView.swift
//  LeGou
//
//  Created by lxm on 2022/11/12.
//

import UIKit
import Lottie

class CompoundSuccessNoGoodsView: LemonBaseView {

    //MARK: --------------------属性--------------------
    
    //MARK: --------------------UI控件--------------------
    @IBOutlet weak var giftContent: UIView!
    
    @IBOutlet weak var price: UILabel!
    
    @IBOutlet weak var sureBtn: UIButton!
    
    //MARK: --------------------生命周期--------------------
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
        bindAction()
        addConstraints()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        setUI()
        bindAction()
        addConstraints()
    }

    //MARK: --------------------UI--------------------
    func setUI() {
        doAnimation()
    }
    
    func playBoxAnimation() {
        let starAnimationView = AnimationView(name: "gift")
        starAnimationView.backgroundBehavior = .pauseAndRestore
        starAnimationView.play(toProgress: 1, loopMode: .loop) { ok in
            
        }
        giftContent.addSubview(starAnimationView)
        starAnimationView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
//            make.width.height.equalTo(180)
        }
    }
    
    func doAnimation() {
        let bgLight = AnimationView(name: "light")
        bgLight.backgroundBehavior = .pauseAndRestore
        bgLight.play(toProgress: 1, loopMode: .playOnce) { [weak self] ok in
            guard let self = self else {return}
            self.playBoxAnimation()
        }
        addSubview(bgLight)
        bgLight.isUserInteractionEnabled = false
        bgLight.snp.makeConstraints { make in
            make.edges.equalToSuperview()
//            make.width.height.equalTo(180)
        }
    }
    
    func addConstraints() {
     
    }
    
    //MARK: --------------------methods--------------------
    func bindAction() {
        
    }
    
    @IBAction func onClose(_ sender: Any) {
        removeFromSuperview()
    }
    
    //MARK: --------------------delegate--------------------

}
